
import type { AttrList, AttrValueVO } from './../src/api/product/attr/type';



// 声明一个数组

let attrList: AttrList = [
  {
    id: 1,
    name: '图书/音像/电子书刊',
    parentId: 0,
  },
  {
    id: 2,
    name: '手机',
    parentId: 0,
  },
  {
    id: 3,
    name: '家用电器',
    parentId: 0,
  },
  {
    id: 4,
    name: '数码',
    parentId: 0,
  },
  {
    id: 5,
    name: '家居家装',
    parentId: 0,
  },
  {
    id: 6,
    name: '电脑办公',
    parentId: 0,
  },
  {
    id: 7,
    name: '厨具',
    parentId: 0,
  },
  {
    id: 8,
    name: '各户化妆',
    parentId: 0,
  },
  {
    id: 9,
    name: '外国图书',
    parentId: 1,
  },
  {
    id: 10,
    name: '外国文学',
    parentId: 1,
  },
  {
    id: 11,
    name: '外国小说',
    parentId: 1,
  },
  {
    id: 12,
    name: '钢铁是怎么样连城',
    parentId: 9,
  },
];





// 新增一个删除属性的函数
const deleteAttr = (id: number) => {
  // 删除属性
  const index = attrList.findIndex((item) => item.id === id);
  if (index !== -1) {
    attrList.splice(index, 1);
  }
}
export default [
  {
    url: '/api/admin/product/getCategory1',
    method: 'get',
    response: (req: any) => {
      // 获取一级分类的数据
      const list = attrList.filter((item) => item.parentId === 0);
      return {
        code: 200,
        message: 'success',
        data: list,
      }
    },
  },
  {
    url: '/api/admin/product/getCategory2/:categoryId',
    method: 'get',
    response: ({ query }: { query: { categoryId: number } }) => {
      // 获取一级分类的数据
      const categoryId = Number(query.categoryId);
      const list = attrList.filter((item) => item.parentId === categoryId);
      return {
        code: 200,
        message: 'success',
        data: list,
      }
    },
  },
  {
    url: '/api/admin/product/getCategory3/:categoryId',
    method: 'get',
    response: ({ query }: { query: { categoryId: number } }) => {
      // 获取一级分类的数据
      const categoryId = Number(query.categoryId);
      const list = attrList.filter((item) => item.parentId === categoryId);
      return {
        code: 200,
        message: 'success',
        data: list,
      }
    },
  },
  {
    url: '/api/admin/product/attrInfoList/:category1Id/:category2Id/:category3Id',
    method: 'get',
    response: ({ query }: { query: { category1Id: number, category2Id: number, category3Id: number } }) => {
      // 获取一级分类的数据
      const category1Id = Number(query.category1Id);
      const category2Id = Number(query.category2Id);
      const category3Id = Number(query.category3Id);
      console.log(category1Id, category2Id, category3Id);
      return {
        code: 200,
        message: 'success',
        data: [
          {
            id: 1,
            attrName: '颜色',
            categoryId: 1,
            categoryLevel: 1,
            attrValueItemList: [
              {
                id: 1,
                valueName: '黑色',
                attrId: 1,
              },
              {
                id: 2,
                valueName: '白色',
                attrId: 1,
              },
              {
                id: 3,
                valueName: '红色',
                attrId: 1,
              },
              {
                id: 4,
                valueName: '蓝色',
                attrId: 1,
              },
              {
                id: 5,
                valueName: '绿色',
                attrId: 1,
              }
              ,
              {
                id: 6,
                valueName: '黑色',
                attrId: 1,
              }

            ]

          },
          {
            id: 2,
            attrName: '内存',
            attrValueItemList: [
              {
                id: 7,
                valueName: '8G',
                attrId: 2,
              },
              {
                id: 8,
                valueName: '16G',
                attrId: 2,
              },
              {
                id: 9,
                valueName: '32G',
                attrId: 2,
              }
            ]

          },
          {
            id: 3,
            name: '手机',
            attrName: '手机',
            categoryId: 2,
            categoryLevel: 3,
            attrValueItemList: [
              {
                id: 10,
                valueName: '小米',
                attrId: 3,
              },
              {
                id: 11,
                valueName: '华为',
                attrId: 3,
              },
              {
                id: 12,
                valueName: '苹果',
                attrId: 3,
              }
            ]
          },
          {
            id: 4,
            name: 'cup型号',
            attrName: 'cup型号',
            categoryId: 1,
            categoryLevel: 3,
            attrValueItemList: [
              {

                id: 13,
                valueName: 'i5',
                attrId: 4,
              },
              {
                id: 14,
                valueName: 'i7',
                attrId: 4,
              }

            ]
          }
        ],
      }
    },
  }, {
    url: '/api/admin/product/saveAttrInfo',
    method: 'post',
    response: ({ body }: { body: AttrValueVO }) => {
      // 获取一级分类的数据
      console.log('body:', body);
      return {
        code: 200,
        message: 'success',
        data: null,
      }
    },
  },
  {
    url: '/api/admin/product/deleteAttr/:id',
    method: 'delete',
    response: ({ query }: { query: { id: number } }) => {
      // 获取一级分类的数据
      const id = Number(query.id);
      console.log('id:', id);
      deleteAttr(id);
      return {
        code: 200,
        message: 'success',
        data: null,
      }
    },
  }
]


//   id: number,
// attrName: string,
// categoryId: number,
// categoryLevel: number,
// attrValueList: AttrValueItemList,